package com.digital.smartgrow.service.businesscenter.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.digital.smartgrow.dao.businesscenter.DynamicFormTemplateMapper;
import com.digital.smartgrow.dto.businesscenter.DynamicFormTemplatePageDTO;
import com.digital.smartgrow.entity.businesscenter.DynamicFormTemplate;
import com.digital.smartgrow.service.businesscenter.DynamicFormTemplateService;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 动态表单模板 服务实现类
 * </p>
 *
 * @author xiewb
 * @since 2022-04-23
 */
@Service
public class DynamicFormTemplateServiceImpl extends ServiceImpl<DynamicFormTemplateMapper, DynamicFormTemplate> implements DynamicFormTemplateService {

    @Override
    public Object getList(DynamicFormTemplatePageDTO pageDTO) {
        Page<DynamicFormTemplate> page = new Page<>(pageDTO.getPageNum(), pageDTO.getPageSize());
        QueryWrapper<DynamicFormTemplate> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(DynamicFormTemplate::getDeleted, 0);
        queryWrapper.eq(pageDTO.getStatus() != null, "status", pageDTO.getStatus());
        queryWrapper.like(StringUtils.isNotBlank(pageDTO.getFormName()), "formName", pageDTO.getFormName());
        return this.page(page, queryWrapper);
    }

    @Override
    public Object getInfo(Integer id) {
        return this.getById(id);
    }
}
